package com.arkisv.log.task;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.arkisv.common.model.StepLog;
import com.arkisv.common.util.SystemUtil;
import com.arkisv.log.dao.StepLogMapper;
import com.arkisv.log.util.Global;

/**
 * 批量插入数据库
 *
 * @author fb
 * @date 2017年3月2日下午3:41:14
 */
@Component
public class BatchStepLogTask {
	@Autowired
	private StepLogMapper stepLogDao;

	/**
	 * 每5s执行一次批量插入数据库
	 */
	@Scheduled(cron = "0/5 * * * * ?")
	public void addStepLog() {
		if(Global.BATCH_ADD_STEP_LOG_LIST.size() == 0) {
			return;
		}
		List<StepLog> batchList = new ArrayList<StepLog>();
		batchList.addAll(Global.BATCH_ADD_STEP_LOG_LIST);
		Global.BATCH_ADD_STEP_LOG_LIST.clear();
		SystemUtil.println("批量插入日志 -> batchList-> size: " + batchList.size());
		// 批量插入数据库
		stepLogDao.batchInsert(batchList); 
	}

}
